package com.lm.ledger.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lm.ledger.service.TransactionService;
import com.lm.ledger.service.TransactionServiceImp;
import com.lm.ledger.utill.Account;
import com.lm.ledger.utill.User;
import com.opensymphony.xwork2.ActionContext;

public class AddTransaction extends TrxAction{

	private List accounts;
	//Ledgerservice service = new Ledgerservice();
	TransactionService service = new TransactionServiceImp();
	
	public List getAccounts() {
		return accounts;
	}

	public void setAccounts(List accounts) {
		this.accounts = accounts;
	}

	public String editTx() throws Exception {		
		return "";
	}
	
	public String deleteTx() throws Exception {	
		System.out.println();
		return "";
	}
	
	public String saveTx() throws Exception {		
		System.out.println("saveTx................");
		return SUCCESS;
	}
	
	public String execute() throws Exception {
		System.out.println("Validating login execute method");		
			return SUCCESS;		
	}
	public String geAlltLocations() throws Exception{
		System.out.println("location ---- "+getLocId());
		setLocations(service.getLocations(getUser().getUserId()));
		return SUCCESS;
	}
	public String getLocns() throws Exception{
		System.out.println("location ---- "+getLocId());
		setLocations(service.getLocations(getUser().getUserId()));
		return SUCCESS;
	}
	
	public String save() throws Exception {
		System.out.println("save  login data");		
		System.out.println("form id -- "+getFormId());
		System.out.println("reason id -- "+getReason());
		System.out.println("loc id -- "+getLocId());
		System.out.println("reason  -- "+getReason());
		System.out.println("amount  -- "+getAmount());
		System.out.println("item  -- "+getItemName());
		System.out.println("interest  -- "+getInterestAmount());
		System.out.println("person  -- "+getPersonId());
		System.out.println("narration  -- "+getNarration());
		System.out.println("trx type  -- "+getTxTye());
		System.out.println("mode  -- "+getMode());
		System.out.println("auth  -- "+getAuthId());
		System.out.println("status  -- "+getStatus());
		System.out.println("trx date "+getTxDate());
		System.out.println("ret date "+getRetDate());
		
		String stat = getStatus();
		if(stat=="false"){
			System.out.println("stat == false");
		}
		if("false".equalsIgnoreCase(stat)){
			System.out.println("stat equal false");
		}
		if(stat=="true"){
			System.out.println("stat == true");
		}
		if("true".equalsIgnoreCase(stat)){
			System.out.println("stat equal true");
		}
		User user = getUser();
		System.out.println("user id save --- "+user.getUserId());
		System.out.println("getName id save --- "+user.getName());
				
		Account account = getAccountDetail();
		if("true".equals(getStatus())){
			account.setAuthId(getUser().getUserId().toString());			
		}
		service.saveNewTrx(account);
		accounts = service.searchAllUserTrx(getUser().getUserId());
		System.out.println("aaaaaaaaaaaaa");
		return SUCCESS;		
	}
	
	private String userRole = "Operator";
	
	public String getUserRole() {
		/*System.out.println("getUserRole.........");
		String userRoleName = (String)getSession().getAttribute("USERROLE");
		System.out.println("getUserRole --- userRoleName "+userRoleName);*/
		return userRole;
	}
	public void setUserRole(String userRole) {
		System.out.println("setUserRole.........");
		this.userRole = userRole;
	}
	
	
}
